package android07.newtop.presenter;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;

import com.jude.beam.expansion.data.BeamDataActivityPresenter;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.util.ArrayList;
import java.util.List;

import android07.newtop.R;
import android07.newtop.activity.PictureActivity;
import android07.newtop.activity.PictureShowActivity;
import android07.newtop.adapter.PictureGalleryAdapter;
import android07.newtop.adapter.PictureShowAdapter;
import android07.newtop.model.PictureModel;
import android07.newtop.model.bean.PictureDetail;
import android07.newtop.model.bean.PictureGallery;
import android07.newtop.utils.JUtils;
import android07.newtop.view.pictureshow.CardScaleHelper;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static android.support.v7.widget.StaggeredGridLayoutManager.VERTICAL;


/**
 * 主页
 * Created by hy on 2016/7/7.
 */
public class PictureShowActivityPresenter extends BeamDataActivityPresenter<PictureShowActivity, PictureDetail> {
    private CardScaleHelper mCardScaleHelper = null;
    PictureShowAdapter adapter;
    int id;
    private static final String TAG = PictureShowActivityPresenter.class.getSimpleName();

    /**
     * activity 刚起床， 睁开眼的那一刻 执行
     *
     * @param view
     */
    @Override
    protected void onCreateView(PictureShowActivity view) {
        super.onCreateView(view);
        //睁开眼，要干啥 ，要喝奶
        Log.d(TAG, "onCreateView: ");
///getDataSubscriber().onNext( 给Activity 填充数据的方法

        id = view.getIntent().getIntExtra("id", 0);
        final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getView(), LinearLayoutManager.HORIZONTAL, false);

        getView().recyclerview.setLayoutManager(linearLayoutManager);


        adapter = new PictureShowAdapter();
        // mRecyclerView绑定scale效果
        getView().recyclerview.setAdapter(adapter);
        onRefresh();

    }


    public void onRefresh() {
        new PictureModel().getPictureDetail(id, new Callback<PictureDetail>() {
            @Override
            public void onResponse(Call<PictureDetail> call, Response<PictureDetail> response) {


                if (response != null && response.body() != null) {


                    adapter.setData(response.body().getList());
                    mCardScaleHelper = new CardScaleHelper();
//                    mCardScaleHelper.setCurrentItemPos(1);
                    mCardScaleHelper.attachToRecyclerView(getView().recyclerview);
                    getView().getToolbar().setTitle(response.body().getTitle());
                }
            }

            @Override
            public void onFailure(Call<PictureDetail> call, Throwable t) {
                JUtils.Toast("网络不给力");

            }
        });


    }

}
